<link rel="stylesheet" href="{{URL::asset('newmobile/css/public.css') }}"/>
<link rel="stylesheet" href="{{URL::asset('newmobile/css/rankdetail.css') }}"/>
<link rel="stylesheet" href="{{URL::asset('newmobile/css/masterlist.css') }}"/>
<link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<style type="text/css">
.list-block {
	margin: 0;
} 
</style>
@include('newmobile.title')
<div class="page-group">
    <div id="page-infinite-scroll-bottom" class="page">
		<div class="content infinite-scroll" data-distance="100">
		    <div class="list-block">
		      	<ul class="list-container">
                    <!-- 排序 -->
                        <div class="oderby">
                            <div>
                                <span>按类型</span>
                                &nbsp;
                                <span class="zheng">全部 <img src="{{ URL::asset('newmobile/images/new_costomer/s.png') }}"></span>
                            </div>
                            <div>
                                <span>按盈亏</span>
                                &nbsp;
                                <span class="ying">全部 <img src="{{ URL::asset('newmobile/images/new_costomer/s.png') }}"></span>
                            </div>
                        </div>
                        <!-- 排序盒子 -->
                        <div class="j_box j_box_one">
                            <div onclick="handanlist(0,select_dealtype,this,1)" class="q">全部 <img src="{{ URL::asset('mobile/image/analystcenter/duihao.png') }}"></div>
                            <div onclick="handanlist(1,select_dealtype,this,1)" class="z">买入 </div>
                            <div onclick="handanlist(2,select_dealtype,this,1)" class="f">卖出 </div>
                        </div>
                        <div class="j_box j_box_two">
                            <div onclick="handanlist(select_type,0,this,2)" class="qy">全&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;部 <img src="{{ URL::asset('mobile/image/analystcenter/duihao.png') }}"></div>
                            <div onclick="handanlist(select_type,1,this,2)" class="y">盈利交易 </div>
                            <div onclick="handanlist(select_type,2,this,2)" class="k">亏损交易 </div>
                        </div>
					<li></li>
		      	</ul>
		    </div>
		    <!-- 加载提示符 -->
		    <div class="infinite-scroll-preloader">
		      	<div class="preloader">
		      	</div>
		    </div>
		</div>
	</div>
</div>
@include('mobile.msg')
<div style="height: 9rem;"></div>
@include('newmobile.footer')
<!-- js引入 -->
<script src="{{URL::asset('mobile/js/public.js') }}"></script>
<script src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script>
var pagess = 0;
var allpage = 2;
var loading = false;
var listurl       = '{{url("/handanhistory")}}';
var analyst_id   = '{{ $info[0]->id}}';
$(function () {
	'use strict';
	//无限滚动
	$(document).on("pageInit", "#page-infinite-scroll-bottom", function(e, id, page) {
//	    var loading = false;
    	// 每次加载添加多少条目
		var itemsPerLoad = 10;
    	// 最多可加载的条目
    	var lastIndex = $('.list-container li').length;
		pullupRefresh(0); //先加载一次数据
    	$(page).on('infinite', function() {
	      	// 如果正在加载，则退出
		  	if (loading) return;
		    // 设置flag
	      	loading = true;
	      	// 模拟1s的加载过程
	      	setTimeout(function() {
	        	// 重置加载flag
	        	loading = false;
	        	if (pagess >= allpage) {
	          		// 加载完毕，则注销无限加载事件，以防不必要的加载
	          		$.detachInfiniteScroll($('.infinite-scroll'));
	          		// 删除加载提示符
	          		$('.infinite-scroll-preloader').html('已加载全部');
	          		return;
	        	}
	        	pagess++; //页面+1
	        	pullupRefresh(0);//更新数据
	        	// 更新最后加载的序号
	        	lastIndex = $('.list-container li').length;
	        	$.refreshScroller();
	      	}, 1000);
	    });
	});
	//加载提示符
	$(document).on("pageInit", "#page-preloader", function(e, id, page) {
	    $(page).on('click','.open-preloader-title', function () {
	      	$.showPreloader('加载中...')
	      	setTimeout(function () {
	        	$.hidePreloader();
	      	}, 2000);
	    });
	    $(page).on('click','.open-indicator', function () {
	      	$.showIndicator();
	      	setTimeout(function () {
	        	$.hideIndicator();
	      	}, 2000);
	    });
	});
  	$.init();
});
var select_type = 0, //交易类型 全局变量
      select_dealtype = 0; //订单盈利亏损 全局变量
//筛选方法
function handanlist(type,dealtype,obj,sq){  
	pagess = 0;
	//调取数据筛选
	select_type = type;  //买入卖出类型
	select_dealtype = dealtype;  //盈亏类型
	pullupRefresh(1);
	// 小对号，修I改样式
	$(obj).siblings().each(function(){
		$(this).html($(this).text());
	});
	if(sq == 1){
        $('.zheng').html($(obj).text()+' <img src="{{ URL::asset("newmobile/images/new_costomer/s.png") }}" />');
    }else{
        $('.ying').html($(obj).text()+' <img src="{{ URL::asset("newmobile/images/new_costomer/s.png") }}" />');    
    }
    $(obj).html($(obj).text()+' <img src="{{ URL::asset("mobile/image/analystcenter/duihao.png") }}" />');
    $('.j_box').hide();
}
//数据加载
function pullupRefresh(num){
	var id  = "{{$info[0]-> id}}";
	$.ajax({
        url: listurl,
        type: "get",
        data:  {analyst_id:id,type:select_type,dealtype:select_dealtype,typename:'',page:pagess},
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        dataType:'json',
        success: function (data) {
        	allpage = data.allpage;
        	if(allpage < 2){
        		$('.infinite-scroll-preloader').html('已加载全部');
        	}else{
        		$('.infinite-scroll-preloader').html('<div class="preloader"></div>');
        	}
            var str='';
            var dataArr = data.arr;
            	if(data){
            		for(var i=0;i<dataArr.length;i++) {
	            		var data = dataArr;
						str+='<section onclick="langxue(this)"><div class="list">';
						str+='<div class="type"><p>'+data[i].chinaname+'</p><p>'+data[i].typename+'</p></div>'; //品种英文
						str+='<div class="direction">';
						if(data[i].buy_status == 1){
	                        str += '<p>卖出</p>';
	                    }else{
	                        str += '<p>买入</p>';
	                    }
						str+='<p>方向</p></div>';
						str+='<div class="profit">';
						if(data[i].final_point >0 ){
	                        str += '<div style="color:#F0364C;">'+data[i].final_point+'</div>';
	                    }else{
	                        str += '<div style="color:#3EB581;">'+data[i].final_point+'</div>';
	                    }
						str+='<p>盈利</p></div></div>';
						str+='<div class="detail"><div class="detail_top"><div class="detail_top_left">';
						str+='<div class="openprice"><p>开仓价</p><p>'+data[i].begin_point+'</p></div>'; //开仓价格
						str+='<div class="onlyprofit"><p>止&nbsp;&nbsp;&nbsp;盈</p><p>'+data[i].target_profit_point+'</p></div>';
						str+='<div class="stoploss"><p>止&nbsp;&nbsp;&nbsp;损</p><p>'+data[i].target_loss_point+'</p></div>';
                        str+='<div class="dingdannum"><p>订单号</p><p>'+data[i].tradeid+'</p></div></div>';
						str+='<div class="detail_top_right">';
						str+='<div class="closeprice"><p>平&nbsp;&nbsp;仓&nbsp;&nbsp;价</p><p>'+data[i].end_point+'</p></div>'; //平仓价格
						str+='<div class="opentime"><p>开仓时间</p><p>'+UnixToDate(data[i].begin_time,false,'',1)+' '+UnixToDate(data[i].begin_time,true,'',0)+'</p></div>';
						str+='<div class="closetime"><p>平仓时间</p><p>'+UnixToDate(data[i].end_time,false,'',1)+' '+UnixToDate(data[i].end_time,true,'',0)+'</p></div></div></div>';
						str+='</div></section>';
					}
            	}else{
            		$('.list-container > li').html('sorry，没有更多数据了');
            	}
				if(num == 1){
					$('.list-container > li').html(str);
				}else{
					$('.list-container > li').append(str);
				}
			}
     	});
};
//时间转换方法
function UnixToDate(unixTime, isFull, timeZone,type) {
    if (typeof (timeZone) == 'number')
    {
        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
    }
    var time = new Date(unixTime * 1000);
    var ymdhis = "";
    if(type){
        ymdhis += time.getFullYear() + ".";
        ymdhis += (time.getMonth()+1)>9?(time.getMonth()+1)+'.':'0'+(time.getMonth()+1) + ".";
        ymdhis += time.getDate()>9?time.getDate():'0'+time.getDate();
    }
    if (isFull === true)
    {
        ymdhis += " " + time.getHours()>9?time.getHours()+ ":":'0'+time.getHours() + ":";
        ymdhis += time.getMinutes()>9?time.getMinutes()+ ":":'0'+time.getMinutes() + ":";
        ymdhis += time.getSeconds()>9?time.getSeconds():'0'+time.getSeconds();
    }
    return ymdhis;
}     
function langxue(obj) {
	$(obj).find('.detail').toggle();
}
$('.ying').click(function(){
    $('.j_box_two').toggle();
    $('.j_box_one').hide();
});
$('.zheng').click(function(){
    $('.j_box_one').toggle();
    $('.j_box_two').hide();
});
</script>  	
<style>
body section.title div:nth-child(1) ,
body section.title div:nth-child(2){
  border-bottom: 0rem;
  color: #9592A7;
}
body section.title div:nth-child(3) {
  border-bottom: 0.1rem solid #3B9CE0;
  color: #cbddeb;
}
.page, .page-group{
    background: #171922;
}
.page-group {
    height: 85%;
    top: 1.5rem;
    border-top: none;
}
.list-block ul:after,
.list-block ul:before {
    background-color: #7390a4;
}
footer {
    z-index: 999999;
    height: auto;
}
/*底部行情应用样式*/
footer ul li:nth-child(1) a {
    color: #3B9CE0;
}
footer ul li:nth-child(1) a i {
  background: url("{{URL::asset('mobile/image/fxs_icond.png')}}") no-repeat center / cover;
}
</style>
